package club.emergency.wechat.feedback.search.provider.impl;

import club.emergency.wechat.common.response.StatusCode;
import club.emergency.wechat.common.response.ResponseEntity;
import club.emergency.wechat.feedback.search.FeedbackSearch;
import club.emergency.wechat.model.feedback.Feedback;
import club.emergency.wechat.persistence.feedback.FeedbackMapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.web.bind.annotation.RestController;

import java.util.Objects;

/**
 * Create with IntelliJ IDEA
 * Project Name: business
 * Package Name: club.emergency.wechat.feedback.search.provider.impl
 * Date: 2018/12/9
 *
 * @author: 快乐的小菌菌
 * Description:
 */
@RestController
public class FeedbackSearchImpl implements FeedbackSearch {

    private FeedbackMapper feedbackMapper;

    public FeedbackSearchImpl(FeedbackMapper feedbackMapper) {
        this.feedbackMapper = feedbackMapper;
    }

    @Override
    public String flipList(Integer categoryNum, Integer deal, Integer pageNo, Integer pageSize) {
        QueryWrapper<Feedback> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq(Objects.nonNull(categoryNum), "category_num", categoryNum);
        queryWrapper.eq(Objects.nonNull(deal), "deal", deal);
        queryWrapper.orderByDesc("modify_time");
        Page<Feedback> page = new Page<>(pageNo, pageSize);
        IPage<Feedback> feedbackIPage = feedbackMapper.selectPage(page, queryWrapper);
        return ResponseEntity.ok(StatusCode.DB_SEARCH_OK, "反馈列表查询成功！", feedbackIPage);
    }
}
